/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.menu.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.menu.entity.OrderGoods3;
import com.thinkgem.jeesite.modules.menu.service.OrderGoods3Service;

/**
 * 订单商品Controller
 * @author dby
 * @version 2020-07-12
 */
@Controller
@RequestMapping(value = "${adminPath}/menu/orderGoods3")
public class OrderGoods3Controller extends BaseController {

	@Autowired
	private OrderGoods3Service orderGoods3Service;
	
	@ModelAttribute
	public OrderGoods3 get(@RequestParam(required=false) String id) {
		OrderGoods3 entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = orderGoods3Service.get(id);
		}
		if (entity == null){
			entity = new OrderGoods3();
		}
		return entity;
	}
	
	@RequiresPermissions("menu:orderGoods3:view")
	@RequestMapping(value = {"list", ""})
	public String list(OrderGoods3 orderGoods3, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<OrderGoods3> page = orderGoods3Service.findPage(new Page<OrderGoods3>(request, response), orderGoods3); 
		model.addAttribute("page", page);
		return "modules/menu/orderGoods3List";
	}

	@RequiresPermissions("menu:orderGoods3:view")
	@RequestMapping(value = "form")
	public String form(OrderGoods3 orderGoods3, Model model) {
		model.addAttribute("orderGoods3", orderGoods3);
		return "modules/menu/orderGoods3Form";
	}

	@RequiresPermissions("menu:orderGoods3:edit")
	@RequestMapping(value = "save")
	public String save(OrderGoods3 orderGoods3, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, orderGoods3)){
			return form(orderGoods3, model);
		}
		orderGoods3Service.save(orderGoods3);
		addMessage(redirectAttributes, "保存订单商品成功");
		return "redirect:"+Global.getAdminPath()+"/menu/orderGoods3/?repage";
	}
	
	@RequiresPermissions("menu:orderGoods3:edit")
	@RequestMapping(value = "delete")
	public String delete(OrderGoods3 orderGoods3, RedirectAttributes redirectAttributes) {
		orderGoods3Service.delete(orderGoods3);
		addMessage(redirectAttributes, "删除订单商品成功");
		return "redirect:"+Global.getAdminPath()+"/menu/orderGoods3/?repage";
	}

}